var globalData = {};
var APIURL = 'http://opc.wanpinghui.com/api';
if(location.href.indexOf('88ba.com')>-1 || location.href.indexOf('wph.com')>-1 ){
    APIURL = 'http://opc.88ba.com/api';
};
//阻止滑动
function _preventDefault(e){
	e.preventDefault(); 
};
function move_stop(){
	document.body.style.overflow = 'hidden';
	window.addEventListener('touchmove', _preventDefault);
};
function move_start(){
	document.body.style.overflow = 'auto';
	window.removeEventListener('touchmove', _preventDefault);
};

$(document).ready(function(){
	// 取本地缓存的im信息
    var im_info = JSON.parse(localStorage.getItem('im_token'));
    var has_im = 0
    if(im_info){
        has_im = 1;
    }

	$.ajax({
		type:"get",
		url:APIURL + "/enterprise/homepage",
		timeout: 30000,
		success:function(data){
			$.extend(true, globalData, data);
			// 如果接口有im_token,存本地;若没有，取本地缓存
        	if(globalData.guest_im_info.im_token){
            	localStorage.setItem('im_token',JSON.stringify(globalData.guest_im_info));
        	}else{
            	globalData.guest_im_info = im_info;
        	}
			set_data(globalData);
			// imInit();
			console.log(globalData);
			console.log(globalData.sem)
		},
		error:function(){
			
		},
	});
	//DOM渲染
	function set_data(data){
		console.log(data);
		globalData.cityToProvince = {
		    "北京市": "北京市",
		    "天津市": "天津市",
		    "石家庄市": "河北省",
		    "唐山市": "河北省",
		    "秦皇岛市": "河北省",
		    "邯郸市": "河北省",
		    "邢台市": "河北省",
		    "保定市": "河北省",
		    "张家口市": "河北省",
		    "承德市": "河北省",
		    "沧州市": "河北省",
		    "廊坊市": "河北省",
		    "衡水市": "河北省",
		    "太原市": "山西省",
		    "大同市": "山西省",
		    "阳泉市": "山西省",
		    "长治市": "山西省",
		    "晋城市": "山西省",
		    "朔州市": "山西省",
		    "晋中市": "山西省",
		    "运城市": "山西省",
		    "忻州市": "山西省",
		    "临汾市": "山西省",
		    "吕梁市": "山西省",
		    "呼和浩特市": "内蒙古自治区",
		    "包头市": "内蒙古自治区",
		    "乌海市": "内蒙古自治区",
		    "赤峰市": "内蒙古自治区",
		    "通辽市": "内蒙古自治区",
		    "鄂尔多斯市": "内蒙古自治区",
		    "呼伦贝尔市": "内蒙古自治区",
		    "巴彦淖尔市": "内蒙古自治区",
		    "乌兰察布市": "内蒙古自治区",
		    "兴安盟": "内蒙古自治区",
		    "锡林郭勒盟": "内蒙古自治区",
		    "阿拉善盟": "内蒙古自治区",
		    "沈阳市": "辽宁省",
		    "大连市": "辽宁省",
		    "鞍山市": "辽宁省",
		    "抚顺市": "辽宁省",
		    "本溪市": "辽宁省",
		    "丹东市": "辽宁省",
		    "锦州市": "辽宁省",
		    "营口市": "辽宁省",
		    "阜新市": "辽宁省",
		    "辽阳市": "辽宁省",
		    "盘锦市": "辽宁省",
		    "铁岭市": "辽宁省",
		    "朝阳市": "辽宁省",
		    "葫芦岛市": "辽宁省",
		    "长春市": "吉林省",
		    "吉林市": "吉林省",
		    "四平市": "吉林省",
		    "辽源市": "吉林省",
		    "通化市": "吉林省",
		    "白山市": "吉林省",
		    "松原市": "吉林省",
		    "白城市": "吉林省",
		    "延边朝鲜族自治州": "吉林省",
		    "哈尔滨市": "黑龙江省",
		    "齐齐哈尔市": "黑龙江省",
		    "鸡西市": "黑龙江省",
		    "鹤岗市": "黑龙江省",
		    "双鸭山市": "黑龙江省",
		    "大庆市": "黑龙江省",
		    "伊春市": "黑龙江省",
		    "佳木斯市": "黑龙江省",
		    "七台河市": "黑龙江省",
		    "牡丹江市": "黑龙江省",
		    "黑河市": "黑龙江省",
		    "绥化市": "黑龙江省",
		    "大兴安岭地区": "黑龙江省",
		    "上海市": "上海市",
		    "南京市": "江苏省",
		    "无锡市": "江苏省",
		    "徐州市": "江苏省",
		    "常州市": "江苏省",
		    "苏州市": "江苏省",
		    "南通市": "江苏省",
		    "连云港市": "江苏省",
		    "淮安市": "江苏省",
		    "盐城市": "江苏省",
		    "扬州市": "江苏省",
		    "镇江市": "江苏省",
		    "泰州市": "江苏省",
		    "宿迁市": "江苏省",
		    "杭州市": "浙江省",
		    "宁波市": "浙江省",
		    "温州市": "浙江省",
		    "嘉兴市": "浙江省",
		    "湖州市": "浙江省",
		    "绍兴市": "浙江省",
		    "金华市": "浙江省",
		    "衢州市": "浙江省",
		    "舟山市": "浙江省",
		    "台州市": "浙江省",
		    "丽水市": "浙江省",
		    "合肥市": "安徽省",
		    "芜湖市": "安徽省",
		    "蚌埠市": "安徽省",
		    "淮南市": "安徽省",
		    "马鞍山市": "安徽省",
		    "淮北市": "安徽省",
		    "铜陵市": "安徽省",
		    "安庆市": "安徽省",
		    "黄山市": "安徽省",
		    "滁州市": "安徽省",
		    "阜阳市": "安徽省",
		    "宿州市": "安徽省",
		    "六安市": "安徽省",
		    "亳州市": "安徽省",
		    "池州市": "安徽省",
		    "宣城市": "安徽省",
		    "福州市": "福建省",
		    "厦门市": "福建省",
		    "莆田市": "福建省",
		    "三明市": "福建省",
		    "泉州市": "福建省",
		    "漳州市": "福建省",
		    "南平市": "福建省",
		    "龙岩市": "福建省",
		    "宁德市": "福建省",
		    "南昌市": "江西省",
		    "景德镇市": "江西省",
		    "萍乡市": "江西省",
		    "九江市": "江西省",
		    "新余市": "江西省",
		    "鹰潭市": "江西省",
		    "赣州市": "江西省",
		    "吉安市": "江西省",
		    "宜春市": "江西省",
		    "抚州市": "江西省",
		    "上饶市": "江西省",
		    "济南市": "山东省",
		    "青岛市": "山东省",
		    "淄博市": "山东省",
		    "枣庄市": "山东省",
		    "东营市": "山东省",
		    "烟台市": "山东省",
		    "潍坊市": "山东省",
		    "济宁市": "山东省",
		    "泰安市": "山东省",
		    "威海市": "山东省",
		    "日照市": "山东省",
		    "莱芜市": "山东省",
		    "临沂市": "山东省",
		    "德州市": "山东省",
		    "聊城市": "山东省",
		    "滨州市": "山东省",
		    "菏泽市": "山东省",
		    "郑州市": "河南省",
		    "开封市": "河南省",
		    "洛阳市": "河南省",
		    "平顶山市": "河南省",
		    "安阳市": "河南省",
		    "鹤壁市": "河南省",
		    "新乡市": "河南省",
		    "焦作市": "河南省",
		    "濮阳市": "河南省",
		    "许昌市": "河南省",
		    "漯河市": "河南省",
		    "三门峡市": "河南省",
		    "南阳市": "河南省",
		    "商丘市": "河南省",
		    "信阳市": "河南省",
		    "周口市": "河南省",
		    "驻马店市": "河南省",
		    "济源市": "河南省",
		    "武汉市": "湖北省",
		    "黄石市": "湖北省",
		    "十堰市": "湖北省",
		    "宜昌市": "湖北省",
		    "襄阳市": "湖北省",
		    "鄂州市": "湖北省",
		    "荆门市": "湖北省",
		    "孝感市": "湖北省",
		    "荆州市": "湖北省",
		    "黄冈市": "湖北省",
		    "咸宁市": "湖北省",
		    "随州市": "湖北省",
		    "恩施土家族苗族自治州": "湖北省",
		    "仙桃市": "湖北省",
		    "潜江市": "湖北省",
		    "天门市": "湖北省",
		    "神农架林区": "湖北省",
		    "长沙市": "湖南省",
		    "株洲市": "湖南省",
		    "湘潭市": "湖南省",
		    "衡阳市": "湖南省",
		    "邵阳市": "湖南省",
		    "岳阳市": "湖南省",
		    "常德市": "湖南省",
		    "张家界市": "湖南省",
		    "益阳市": "湖南省",
		    "郴州市": "湖南省",
		    "永州市": "湖南省",
		    "怀化市": "湖南省",
		    "娄底市": "湖南省",
		    "湘西土家族苗族自治州": "湖南省",
		    "广州市": "广东省",
		    "韶关市": "广东省",
		    "深圳市": "广东省",
		    "珠海市": "广东省",
		    "汕头市": "广东省",
		    "佛山市": "广东省",
		    "江门市": "广东省",
		    "湛江市": "广东省",
		    "茂名市": "广东省",
		    "肇庆市": "广东省",
		    "惠州市": "广东省",
		    "梅州市": "广东省",
		    "汕尾市": "广东省",
		    "河源市": "广东省",
		    "阳江市": "广东省",
		    "清远市": "广东省",
		    "东莞市": "广东省",
		    "中山市": "广东省",
		    "潮州市": "广东省",
		    "揭阳市": "广东省",
		    "云浮市": "广东省",
		    "南宁市": "广西壮族自治区",
		    "柳州市": "广西壮族自治区",
		    "桂林市": "广西壮族自治区",
		    "梧州市": "广西壮族自治区",
		    "北海市": "广西壮族自治区",
		    "防城港市": "广西壮族自治区",
		    "钦州市": "广西壮族自治区",
		    "贵港市": "广西壮族自治区",
		    "玉林市": "广西壮族自治区",
		    "百色市": "广西壮族自治区",
		    "贺州市": "广西壮族自治区",
		    "河池市": "广西壮族自治区",
		    "来宾市": "广西壮族自治区",
		    "崇左市": "广西壮族自治区",
		    "海口市": "海南省",
		    "三亚市": "海南省",
		    "三沙市": "海南省",
		    "儋州市": "海南省",
		    "五指山市": "海南省",
		    "琼海市": "海南省",
		    "文昌市": "海南省",
		    "万宁市": "海南省",
		    "东方市": "海南省",
		    "定安县": "海南省",
		    "屯昌县": "海南省",
		    "澄迈县": "海南省",
		    "临高县": "海南省",
		    "白沙黎族自治县": "海南省",
		    "昌江黎族自治县": "海南省",
		    "乐东黎族自治县": "海南省",
		    "陵水黎族自治县": "海南省",
		    "保亭黎族苗族自治县": "海南省",
		    "琼中黎族苗族自治县": "海南省",
		    "重庆市": "重庆市",
		    "重庆市郊县": "重庆市",
		    "成都市": "四川省",
		    "自贡市": "四川省",
		    "攀枝花市": "四川省",
		    "泸州市": "四川省",
		    "德阳市": "四川省",
		    "绵阳市": "四川省",
		    "广元市": "四川省",
		    "遂宁市": "四川省",
		    "内江市": "四川省",
		    "乐山市": "四川省",
		    "南充市": "四川省",
		    "眉山市": "四川省",
		    "宜宾市": "四川省",
		    "广安市": "四川省",
		    "达州市": "四川省",
		    "雅安市": "四川省",
		    "巴中市": "四川省",
		    "资阳市": "四川省",
		    "阿坝藏族羌族自治州": "四川省",
		    "甘孜藏族自治州": "四川省",
		    "凉山彝族自治州": "四川省",
		    "贵阳市": "贵州省",
		    "六盘水市": "贵州省",
		    "遵义市": "贵州省",
		    "安顺市": "贵州省",
		    "毕节市": "贵州省",
		    "铜仁市": "贵州省",
		    "黔西南布依族苗族自治州": "贵州省",
		    "黔东南苗族侗族自治州": "贵州省",
		    "黔南布依族苗族自治州": "贵州省",
		    "昆明市": "云南省",
		    "曲靖市": "云南省",
		    "玉溪市": "云南省",
		    "保山市": "云南省",
		    "昭通市": "云南省",
		    "丽江市": "云南省",
		    "普洱市": "云南省",
		    "临沧市": "云南省",
		    "楚雄彝族自治州": "云南省",
		    "红河哈尼族彝族自治州": "云南省",
		    "文山壮族苗族自治州": "云南省",
		    "西双版纳傣族自治州": "云南省",
		    "大理白族自治州": "云南省",
		    "德宏傣族景颇族自治州": "云南省",
		    "怒江傈僳族自治州": "云南省",
		    "迪庆藏族自治州": "云南省",
		    "拉萨市": "西藏自治区",
		    "日喀则市": "西藏自治区",
		    "昌都市": "西藏自治区",
		    "山南市": "西藏自治区",
		    "那曲地区": "西藏自治区",
		    "阿里地区": "西藏自治区",
		    "林芝市": "西藏自治区",
		    "西安市": "陕西省",
		    "铜川市": "陕西省",
		    "宝鸡市": "陕西省",
		    "咸阳市": "陕西省",
		    "渭南市": "陕西省",
		    "延安市": "陕西省",
		    "汉中市": "陕西省",
		    "榆林市": "陕西省",
		    "安康市": "陕西省",
		    "商洛市": "陕西省",
		    "兰州市": "甘肃省",
		    "嘉峪关市": "甘肃省",
		    "金昌市": "甘肃省",
		    "白银市": "甘肃省",
		    "天水市": "甘肃省",
		    "武威市": "甘肃省",
		    "张掖市": "甘肃省",
		    "平凉市": "甘肃省",
		    "酒泉市": "甘肃省",
		    "庆阳市": "甘肃省",
		    "定西市": "甘肃省",
		    "陇南市": "甘肃省",
		    "临夏回族自治州": "甘肃省",
		    "甘南藏族自治州": "甘肃省",
		    "西宁市": "青海省",
		    "海东市": "青海省",
		    "海北藏族自治州": "青海省",
		    "黄南藏族自治州": "青海省",
		    "海南藏族自治州": "青海省",
		    "果洛藏族自治州": "青海省",
		    "玉树藏族自治州": "青海省",
		    "海西蒙古族藏族自治州": "青海省",
		    "银川市": "宁夏回族自治区",
		    "石嘴山市": "宁夏回族自治区",
		    "吴忠市": "宁夏回族自治区",
		    "固原市": "宁夏回族自治区",
		    "中卫市": "宁夏回族自治区",
		    "乌鲁木齐市": "新疆维吾尔自治区",
		    "克拉玛依市": "新疆维吾尔自治区",
		    "吐鲁番市": "新疆维吾尔自治区",
		    "哈密市": "新疆维吾尔自治区",
		    "昌吉回族自治州": "新疆维吾尔自治区",
		    "博尔塔拉蒙古自治州": "新疆维吾尔自治区",
		    "巴音郭楞蒙古自治州": "新疆维吾尔自治区",
		    "阿克苏地区": "新疆维吾尔自治区",
		    "克孜勒苏柯尔克孜自治州": "新疆维吾尔自治区",
		    "喀什地区": "新疆维吾尔自治区",
		    "和田地区": "新疆维吾尔自治区",
		    "伊犁哈萨克自治州": "新疆维吾尔自治区",
		    "塔城地区": "新疆维吾尔自治区",
		    "阿勒泰地区": "新疆维吾尔自治区",
		    "石河子市": "新疆维吾尔自治区",
		    "阿拉尔市": "新疆维吾尔自治区",
		    "图木舒克市": "新疆维吾尔自治区",
		    "五家渠市": "新疆维吾尔自治区",
		    "北屯市": "新疆维吾尔自治区",
		    "铁门关市": "新疆维吾尔自治区",
		    "双河市": "新疆维吾尔自治区",
		    "可克达拉市": "新疆维吾尔自治区",
		    "昆玉市": "新疆维吾尔自治区",
		    "中西区": "香港特别行政区",
		    "湾仔区": "香港特别行政区",
		    "东区": "香港特别行政区",
		    "南区": "香港特别行政区",
		    "油尖旺区": "香港特别行政区",
		    "深水埗区": "香港特别行政区",
		    "九龙城区": "香港特别行政区",
		    "黄大仙区": "香港特别行政区",
		    "观塘区": "香港特别行政区",
		    "荃湾区": "香港特别行政区",
		    "屯门区": "香港特别行政区",
		    "元朗区": "香港特别行政区",
		    "北区": "香港特别行政区",
		    "大埔区": "香港特别行政区",
		    "西贡区": "香港特别行政区",
		    "沙田区": "香港特别行政区",
		    "葵青区": "香港特别行政区",
		    "离岛区": "香港特别行政区",
		    "香港特别行政区": "香港特别行政区",
		    "澳门特别行政区": "澳门特别行政区",
		    "花地玛堂区": "澳门特别行政区",
		    "花王堂区": "澳门特别行政区",
		    "望德堂区": "澳门特别行政区",
		    "大堂区": "澳门特别行政区",
		    "风顺堂区": "澳门特别行政区",
		    "嘉模堂区": "澳门特别行政区",
		    "路凼填海区": "澳门特别行政区",
		    "圣方济各堂区": "澳门特别行政区",
		    "台湾省": "台湾省"
		};
		//title
		$('title').html(data.homepage.title);
		//=====================================================================================================================================
		//定位城市
		$('#CitySelector-current .currCity').html(data.ip_info.city);
		$('#CitySelector-current').attr('data-city',data.ip_info.city);
		$('.sel-city').html(data.ip_info.city);
		//=====================================================================================================================================
		//首屏渲染
		$('.banner').css('background-image','url('+data.homepage.first_screen_background+')')
		$('.banner h2').html(data.homepage.first_screen_title);
		$('.banner h4').html(data.homepage.first_screen_subtitle);
		$('.get_price h5 i').html(data.offer_cnt);
		$('.pos-city').html("<span class='iconfont icon-location font_color'></span><span class='sel-city font_color'>"+data.ip_info.city+"</span>");
		//=====================================================================================================================================
		//logo图
		$('.logo').attr('src',data.homepage.header_logo);
		$('.modal_logo').attr('src',data.homepage.header_logo);
		//=====================================================================================================================================
		//各块副标题
		$('.project_case .the_second_title').html(data.homepage.project_subtitle);
		$('.guarantee_system .the_second_title').html(data.homepage.security_subtitle);
		$('.product_show .the_second_title').html(data.homepage.product_subtitle);
		$('.partner .the_second_title').html(data.homepage.partner_subtitle);
		$('.about_us .the_second_title').html(data.homepage.about_us_subtitle);
		//合作伙伴图片
		$('.partner_img img').attr('src',data.homepage.partner_img)
		//=====================================================================================================================================
		// 移除遮羞布
        $('#fig-leaf').remove();

		//项目案例渲染与轮播
		var project_data = data.projects;
		var project_list = "";
		var project_slide_list = "";
		var project_id_arr = [];
		var project_title_arr = [];
		console.log(project_data);
		$.each(project_data, function(i,item) {
			project_slide_list += 	"<div class='swiper-slide'><div class='case_box'><img src='"+item.project_img+"'/><h3 class='case_price font_semibold'>造价约￥<span class='font_color'>"+item.project_cost+"</span></h3><p class='case_size font_regular'>"+item.project_title+"</p><p class='case_time font_light'>"+item.project_text+"</p></div></div>"
			if(project_data[i].project_type_id == -1){
				
			}else{
				project_id_arr.push(project_data[i].project_type_id);	
			}	

		});
		project_id_arr = project_id_arr.sort();
		console.log(project_id_arr)
		for (var i=0;i<project_id_arr.length;i++) {
			if(project_id_arr[i]==project_id_arr[i+1]){
				project_id_arr.splice(i,1);
				i--;
			}
		}
		console.log(project_id_arr);
		for (var i=0;i<project_id_arr.length;i++) {
			for (var k=0;k<project_data.length;k++) {
				if(project_id_arr[i] == project_data[k].project_type_id){
					project_title_arr.push(project_data[k].project_type_display);
					break;
				}
			};	
		};
		console.log(project_title_arr);
		for (var i=0;i<project_id_arr.length;i++) {
			project_list += "<li class='choose' project_id='"+project_id_arr[i]+"'>"+project_title_arr[i]+"</li>";
		};
		if(project_list == ""){
			$('.project_case .choose_list .default_choose').hide();
		}else{
			$('.project_case .choose_list .default_choose').after(project_list);
		};
		$('#swiper-container_project_case .swiper-wrapper').html(project_slide_list);
		var mySwiper_project_case = new Swiper('#swiper-container_project_case', {
			slidesPerView : 1,
			centeredSlides : true,
			spaceBetween : 16,
			loop :true,
            autoplay : 5000,
            autoplayDisableOnInteraction : false
		});
		//项目案例tab选择
		$('.project_case .choose_list').on('click','.choose',function(){
			$(this).addClass('default_choose');
			$('.default_choose').css('background-color',globalData.homepage.base_color_num);
			$('.default_choose').css('border-color',globalData.homepage.base_color_num);
			$(this).siblings('.choose').removeClass('default_choose');
			$(this).siblings('.choose').css('background-color','#FFFFFF');
			$(this).siblings('.choose').css('border-color','#EAEAEA');
			console.log($(this).attr('project_id'));
			var project_id = $(this).attr('project_id');
			var project_data = globalData.projects;
			var project_slide_list = "";
			if(project_id == 'all'){
				$.each(project_data, function(i,item) {
					project_slide_list += 	"<div class='swiper-slide'><div class='case_box'><img src='"+item.project_img+"'/><h3 class='case_price font_semibold'>造价约￥<span class='font_color'>"+item.project_cost+"</span></h3><p class='case_size font_regular'>"+item.project_title+"</p><p class='case_time font_light'>"+item.project_text+"</p></div></div>"
				});
			}else{
				$.each(project_data, function(i,item) {
					if(item.project_type_id == project_id){
						project_slide_list += 	"<div class='swiper-slide'><div class='case_box'><img src='"+item.project_img+"'/><h3 class='case_price font_semibold'>造价约￥<span class='font_color'>"+item.project_cost+"</span></h3><p class='case_size font_regular'>"+item.project_title+"</p><p class='case_time font_light'>"+item.project_text+"</p></div></div>"
					}else{
						
					}
				});
			};
			$('#swiper-container_project_case .swiper-wrapper').html(project_slide_list);
			$('.font_color').css('color',globalData.homepage.base_color_num)
			mySwiper_project_case.update(true);
			mySwiper_project_case.reLoop();
		});
		//=====================================================================================================================================
		//保障体系渲染
		var securities_data = data.securities;
		var securities_list = "";
		//保障体系id和图标的对应关系
		var sec_dirc = [
			{
			    "index":1,
			    "iconfont":"icon-changjiazhixiao"
			},
			{	
				"index":2,
			    "iconfont":"icon-mianfeibaojia"
			},
			{
				"index":3,
			    "iconfont":"icon-zhiliangbaozheng"
			},
			{
				"index":4,
			    "iconfont":"icon-kuaisushangmenanzhuang"
			},
			{
				"index":5,
			    "iconfont":"icon-xiaoshishouhou"
			},
			{
				"index":6,
			    "iconfont":"icon-jiageshihui"
			},
			{
				"index":7,
			    "iconfont":"icon-hangyelingxian"
			},
			{
				"index":8,
			    "iconfont":"icon-xiananzhuanghoufukuanx"
			}
		];
		$.each(securities_data, function(i,item) {
			var iconfont_str = "";
			$.each(sec_dirc, function(k,data) {
				if(item.security_id == data.index){
					iconfont_str = data.iconfont;
				}
			});
			securities_list += "<li><i class='iconfont font_color "+iconfont_str+"'></i><h5 class='font_regular'>"+item.security_display+"</h5><p class='font_light'>"+item.security_text+"</p></li>"
		});
		$('.guarantee_system_list').html(securities_list);
		//=====================================================================================================================================
		//产品展示渲染与轮播
		var product_data = data.products;
		var product_list = "";
		var product_slide_list = "";
		var product_id_arr = [];
		var product_title_arr = [];
		$.each(product_data, function(i,item) {
			product_slide_list += "<div class='swiper-slide'><div class='product_box'><img src='"+item.product_img+"'/><p class='product_name font_light'>"+item.product_title+"</p></div></div>";
			if(product_data[i].product_type_id == -1){
				
			}else{
				product_id_arr.push(product_data[i].product_type_id);	
			}	
		});
		product_id_arr = product_id_arr.sort();
		for (var i=0;i<product_id_arr.length;i++) {
			if(product_id_arr[i]==product_id_arr[i+1]){
				product_id_arr.splice(i,1);
				i--;
			}
		}
		for (var i=0;i<product_id_arr.length;i++) {
			for (var k=0;k<product_data.length;k++) {
				if(product_id_arr[i] == product_data[k].product_type_id){
					product_title_arr.push(product_data[k].product_type_display);
					break;
				}
			};	
		};
		for (var i=0;i<product_id_arr.length;i++) {
			product_list += "<li class='choose' product_id='"+product_id_arr[i]+"'>"+product_title_arr[i]+"</li>";
		};
		if(product_list == ""){
			$('.product_show .choose_list .default_choose').hide();
		}else{
			$('.product_show .choose_list .default_choose').after(product_list);	
		}
		$('#swiper-container_product_show .swiper-wrapper').html(product_slide_list);
		var mySwiper_product_show = new Swiper('#swiper-container_product_show', {
			slidesPerView : 1,
			centeredSlides : true,
			spaceBetween : 16,
			loop :true,
            autoplay : 5000,
            autoplayDisableOnInteraction : false,
		});
		//产品展示tab
		$('.product_show .choose_list').on('click','.choose',function(){
			$(this).addClass('default_choose');
			$('.default_choose').css('background-color',globalData.homepage.base_color_num);
			$('.default_choose').css('border-color',globalData.homepage.base_color_num);
			$(this).siblings('.choose').removeClass('default_choose');
			$(this).siblings('.choose').css('background-color','#FFFFFF');
			$(this).siblings('.choose').css('border-color','#EAEAEA');
			console.log($(this).attr('product_id'));
			var product_id = $(this).attr('product_id');
			var product_data = globalData.products;
			var product_slide_list = "";
			if(product_id == 'all'){
				$.each(product_data, function(i,item) {
					product_slide_list += "<div class='swiper-slide'><div class='product_box'><img src='"+item.product_img+"'/><p class='product_name font_light'>"+item.product_title+"</p></div></div>"
				});
			}else{
				console.log(1)
				console.log(product_data)
				$.each(product_data, function(i,item) {
					if(item.product_type_id == product_id){
						product_slide_list += "<div class='swiper-slide'><div class='product_box'><img src='"+item.product_img+"'/><p class='product_name font_light'>"+item.product_title+"</p></div></div>"
					}else{
						
					}
				});
			};
			$('#swiper-container_product_show .swiper-wrapper').html(product_slide_list);
			$('.font_color').css('color',globalData.homepage.base_color_num)
			mySwiper_product_show.update(true);
			mySwiper_product_show.reLoop();
		});
		//======================================================================================================================================
		//荣誉资质轮播
		var honor_data = data.honours;
		var honor_slide_list = "";
		$.each(honor_data, function(i,item) {
			honor_slide_list += "<div class='swiper-slide'><div class='honor_box'><img src='"+item.honour_img+"'/><p class='honor_info font_light'>"+item.honour_title+"</p></div></div>"
		});
		$('#swiper-container_honor .swiper-wrapper').html(honor_slide_list);
		var mySwiper_honor = new Swiper('#swiper-container_honor', {
			slidesPerView : 1,
			centeredSlides : true,
			spaceBetween : 16,
			loop :true,
            autoplay : 5000,
            autoplayDisableOnInteraction : false,
		});
		//======================================================================================================================================
		//公司规模轮播
		var company_size_data = data.pictures;
		var company_size_list = "";
		$('.company_detail .legal_person .legal_person_info .legal_person_info_name').html(data.homepage.legal_person_name);
		$('.company_detail .legal_person img').attr('src',data.homepage.legal_person_avatar);
		$('.company_detail .legal_person img').attr('src',data.homepage.legal_person_avatar);
		$('.company_detail .company_info .company_info_money').html(data.homepage.registered_capital);
		$('.company_detail .company_info .company_info_time').html(data.homepage.registered_date);
		$('.company_detail .company_info .company_info_people').html(data.homepage.staff_size);
		$.each(company_size_data, function(i,item) {
			company_size_list += "<div class='swiper-slide'><div class='company_size_box'><img src='"+item.picture_img+"'/><p class='company_size_info font_medium'>"+item.picture_title+"</p></div></div>"
		});
		$('#swiper-container_company_size .swiper-wrapper').html(company_size_list);
		var mySwiper_company_size = new Swiper('#swiper-container_company_size', {
			pagination : '.swiper-pagination',
            loop :true,
            autoplay : 5000,
            autoplayDisableOnInteraction : false,
		});
		//======================================================================================================================================
		//媒体报道
		var media_data = data.media_reports;
		var media_slide_list = "";
        if(data.media_reports.length == 0){
            $('.media').hide();
        }else{
            $.each(media_data, function(i,item) {
                media_slide_list += "<div class='swiper-slide'><div class='media_box'><img src='"+item.report_img+"'/><p class='media_info_title font_light'>"+item.report_title+"</p><p class='media_info_detail font_light'>"+item.report_text+"</p></div></div>"
            });
            $('#swiper-container_media .swiper-wrapper').html(media_slide_list);
            var mySwiper_media = new Swiper('#swiper-container_media', {
                slidesPerView : 1,
                centeredSlides : true,
                spaceBetween : 16,
                loop :true,
                autoplay : 5000,
                autoplayDisableOnInteraction : false
            });
        }

		//======================================================================================================================================
		//底部
		$('.footer .customer_service .customer_service_num a').html(data.homepage.virtual_number);
		$('.footer .customer_service .customer_service_num a').attr('href','tel:'+data.homepage.virtual_number);
		$('.preparation_number span').html(data.enterprise_name);
		$('.preparation_number p').html(data.homepage.safety_record+" "+data.homepage.record_number);
		$('.footer_btns a').attr('href','tel:'+data.homepage.virtual_number);
		$('.btns a').attr('href','tel:'+data.homepage.virtual_number);
		//=====================================================================================================================================
		//颜色
		$('.back_color').css('background-color',data.homepage.base_color_num);
		$('.border_color').css('border-color',data.homepage.base_color_num);
		$('.font_color').css('color',data.homepage.base_color_num);
		$('.banner_color').css('background-color',data.first_screen_color_num);
		$('.default_choose').css('background-color',data.homepage.base_color_num);
		$('.default_choose').css('border-color',data.homepage.base_color_num);
		$('.project_case').css('background-color',data.homepage.project_color_num);
		$('.guarantee_system').css('background-color',data.homepage.security_color_num);
		$('.product_show').css('background-color',data.homepage.product_color_num);
		$('.partner').css('background-color',data.homepage.partner_color_num);
		$('.about_us').css('background-color',data.homepage.about_us_color_num);
		$('.about_us .honor').css('background-color',data.homepage.honour_color_num);
		$('.about_us .company_size').css('background-color',data.homepage.scale_color_num);
		$('.about_us .media').css('background-color',data.homepage.report_color_num);
		//=====================================================================================================================================
		//客服资料
		$('#ChatRoom h4').html(data.im_info.nickname);
		$('#ChatRoom a').html(data.homepage.virtual_number);
		$('#ChatRoom a').attr('href','tel:'+data.homepage.virtual_number);
		$('#ChatRoom img').attr('src',data.im_info.avatar);
	};
	// banner页 计价器底部 滚动显示的数据
	function ScrollShowFakeData() {
	    var sec_num_mobile = ['3','5','7','8'];// 手机号第二位，选常用的四个
	    var dom = '';
	    for(var i=0;i<10;i++){
	        var mob = '1'+ sec_num_mobile[parseInt(Math.random()*3)] + parseInt(Math.random()*9) + '****' + (parseInt(Math.random()*8999+1000));
	        var cost = parseInt(Math.random()*4950)*100 + 5000;
	        var item = "<p><span class='tel'>"+mob+"</span>获得报价<span class='money font_color'>"+cost+"</span>元</p>";
	        dom += item;
	    }
	    $('.price_detail_list').html(dom);
	
	    var j=0;
	    setInterval(function () {
	        j++;
	        if(j>=10){
	            j = 0;
	            $('.price_detail_list').css('top','0');
	        }
	        $('.price_detail_list').animate({'top':'-' +0.15*j +'rem'},300);
	    },3000);
	};
	ScrollShowFakeData();
	//弹出导航
	$('.manu').click(function(){
		$('#modal').slideToggle(300,function(){
			move_stop();
		});
	});
	//关闭导航
	$('.close_btn').click(function(){
		$('#modal').slideToggle(300,function(){
			move_start();
		});
	});
	//导航页打开客服
	$('.btns_talk').click(function(){
		openChatRoom();
		$('#ChatRoom').addClass('form_manu');
		move_stop();
	});
	//导航跳转
	$('.manu_list').children('li').click(function(){
		move_start();
		var the_url = $(this).attr('class').split('-');
		the_url = '.'+the_url[1];
		$('#modal').slideToggle(300,function(){
			var margin_top = parseInt($('.head').css('height'));
			$("html, body").animate({  
	            scrollTop: $(the_url).offset().top - margin_top + "px"  
	        }, {  
	            duration: 300,  
	            easing: "swing"  
	        });
		}); 
	});
	//滚动监听
	$(window).scroll(function(){
		var scroll_height = $('.banner').offset().top + parseInt($('.banner').css('height')) + parseInt($('.banner').css('paddingBottom'));
		if($(window).scrollTop() >= scroll_height){
			$('.footer_btns').fadeIn(300);
			$('.customer_service_btn').fadeIn(300);
			$('#main').css('marginBottom','0.6rem');
		}else{
			$('.footer_btns').fadeOut(300);
			$('.customer_service_btn').fadeOut(300);
			$('#main').css('marginBottom','0');
		}
	});
	//点击底部获取报价
	$('.footer_btns_price').click(function(){
		$("html, body").animate({  
            scrollTop: $('.banner').offset().top + "px"  
        }, {  
            duration: 300,  
            easing: "swing"  
        });	
	});

	//datapicker加载本地资源
	//场景picker资源
	var all_scene = [
		{
			text:"商业广告",
			value:[8,4.5]
		},
		{
			text:"门头屏",
			value:[3,0.5]
		},
		{
			text:"舞台租赁",
			value:[6,4]
		},
		{
			text:"交通诱导",
			value:[3,0.5]
		},
		{
			text:"安防监控",
			value:[5,3]
		},
	];
	var picker = new mui.PopPicker();
	picker.setData(all_scene);
	$('.use_scene_input').on('click',function(){
		$('.use_scene_input').css('border-color',globalData.homepage.base_color_num);
		picker.show(function (selectItems) {
			$('.use_scene_input').html(selectItems[0].text);
			$('.screen_size_height input').val(selectItems[0].value[1]);
			$('.screen_size_width input').val(selectItems[0].value[0])
	    })
	});
	$('.screen_size_div input').focus(function(){
		$(this).parents('.screen_size_div').css('border-color',globalData.homepage.base_color_num);
		$('.use_scene_input').css('border-color','rgba(158, 159, 161, 1)');
	});
	$('.screen_size_div input').blur(function(){
		$(this).parents('.screen_size_div').css('border-color','rgba(158, 159, 161, 1)');
	});
	$('.use_tel .banner_input').focus(function(){
		$(this).css('border-color',globalData.homepage.base_color_num);
		$('.use_scene_input').css('border-color','rgba(158, 159, 161, 1)');
	});
	$('.use_tel .banner_input').blur(function(){
		$(this).css('border-color','rgba(158, 159, 161, 1)');
	});
	//计算报价
	//遮罩
	var mask = mui.createMask(function(){
		$('.commit_success').fadeOut(300);
		$('.commit_fail').fadeOut(300);
		move_start();
	});
	$('.btn').click(function(){
		//手机号验证
		var tel_reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;  
		var user_tel = $('.use_tel input').val();
		var choosecity = globalData.choosecity;//城市
		var chooseprov = globalData.chooseprov;//省份
		if(user_tel == ""){
			$('.tel_error').show();
		}else if(!tel_reg.test(user_tel)){
			$('.tel_error').show();
		}else{
			$('.tel_error').hide();
			//在globalData中新增choosecity和chooseprov字段判断是定位城市还是选择城市
			if(choosecity == undefined || chooseprov == undefined){
				choosecity = globalData.ip_info.city;
				chooseprov = globalData.ip_info.prov;
			};
			var data = {
				"mobile":user_tel,
				"cate": 1,
				"prov": chooseprov,
				"city": choosecity,
				"sem": globalData.sem,
				"enterprise_source":"MO"
			};
			$.ajax({
				"url": APIURL+ "/Client/Demand/postDraft",
				"type": "POST",
				"data": data,
				success: function (json) {
					if(json.status == 200){
						mask.show();
						$('.commit_success').fadeIn(300);
						move_stop();
						console.log(json);
					}else{
						$('.commit_fail p').html(json.msg);
						mask.show();
						$('.commit_fail').fadeIn(300);
						move_stop();
					}
				}
			});
		}
	});
	//关闭报价成功弹窗
	$('.close_window').click(function(){
		$('.commit_success').fadeOut(300);
		mask.close();
		move_start();
	});
	//关闭报价失败弹窗
	$('.commit_fail_close').click(function(){
		$('.commit_fail').fadeOut(300);
		mask.close();
		move_start();
	});
});

 // 打开客服聊天窗
function openChatRoom() {
	$('#ChatRoom').fadeIn(300);
    // 切换当前会话为工程商，且将消息列表滚动到底部
    setCurrSession(globalData.im_info.accid);
    $('.msg-pane')[0].scrollTop = $('.msg-pane')[0].scrollHeight;
    move_stop();
} // 关闭客服聊天窗
function closeChatRoom() {
	$('#ChatRoom').fadeOut(300);
    // 切换当前会话为空
    setCurrSession('');
    if(!$('#ChatRoom').hasClass('form_manu')){
    	move_start();	
    }else{
    	$('#ChatRoom').removeClass('form_manu');
    };
};
// 打开城市选择器
function toggleCity() {
    $('#CitySelector').fadeToggle();
}
/** 城市列表渲染 */
(function () {
    var cityList = [{"letter":"A","list":["阿拉善盟","鞍山市","安庆市","安阳市","阿坝藏族羌族自治州","安顺市","阿里地区","安康市","阿克苏地区","阿勒泰地区","阿拉尔市","澳门特别行政区"]},{"letter":"B","list":["北京市","保定市","包头市","巴彦淖尔市","本溪市","白山市","白城市","蚌埠市","亳州市","滨州市","北海市","百色市","白沙黎族自治县","保亭黎族苗族自治县","巴中市","毕节市","保山市","宝鸡市","白银市","博尔塔拉蒙古自治州","巴音郭楞蒙古自治州","北屯市"]},{"letter":"C","list":["承德市","沧州市","长治市","赤峰市","长春市","常州市","滁州市","池州市","长沙市","常德市","郴州市","潮州市","崇左市","澄迈县","昌江黎族自治县","成都市","楚雄彝族自治州","昌都市","昌吉回族自治州"]},{"letter":"D","list":["大同市","大连市","丹东市","大庆市","大兴安岭地区","东营市","德州市","东莞市","儋州市","东方市","定安县","德阳市","达州市","大理白族自治州","德宏傣族景颇族自治州","迪庆藏族自治州","定西市"]},{"letter":"E","list":["鄂尔多斯市","鄂州市","恩施土家族苗族自治州"]},{"letter":"F","list":["抚顺市","阜新市","阜阳市","福州市","莆田市","抚州市","佛山市","防城港市"]},{"letter":"G","list":["赣州市","广州市","桂林市","贵港市","广元市","广安市","甘孜藏族自治州","贵阳市","甘南藏族自治州","果洛藏族自治州","固原市"]},{"letter":"H","list":["邯郸市","衡水市","呼和浩特市","呼伦贝尔市","葫芦岛市","哈尔滨市","鹤岗市","黑河市","淮安市","杭州市","湖州市","合肥市","淮南市","淮北市","黄山市","菏泽市","鹤壁市","黄石市","黄冈市","衡阳市","怀化市","惠州市","河源市","贺州市","河池市","海口市","红河哈尼族彝族自治州","汉中市","海东市","海北藏族自治州","黄南藏族自治州","海南藏族自治州","海西蒙古族藏族自治州","哈密市","和田地区"]},{"letter":"J","list":["晋城市","晋中市","锦州市","吉林市","鸡西市","佳木斯市","嘉兴市","金华市","景德镇市","九江市","吉安市","济南市","济宁市","焦作市","济源市","荆门市","荆州市","江门市","揭阳市","嘉峪关市","金昌市","酒泉市"]},{"letter":"K","list":["开封市","昆明市","克拉玛依市","克孜勒苏柯尔克孜自治州","喀什地区","可克达拉市","昆玉市"]},{"letter":"L","list":["廊坊市","临汾市","吕梁市","辽阳市","辽源市","连云港市","丽水市","六安市","龙岩市","莱芜市","临沂市","聊城市","洛阳市","娄底市","柳州市","来宾市","临高县","乐东黎族自治县","陵水黎族自治县","泸州市","乐山市","凉山彝族自治州","六盘水市","丽江市","临沧市","拉萨市","林芝市","兰州市","陇南市","临夏回族自治州"]},{"letter":"M","list":["牡丹江市","马鞍山市","茂名市","梅州市","绵阳市","眉山市"]},{"letter":"N","list":["南京市","南通市","宁波市","南平市","宁德市","南昌市","南阳市","南宁市","内江市","南充市","怒江傈僳族自治州","那曲地区"]},{"letter":"P","list":["盘锦市","萍乡市","平顶山市","濮阳市","攀枝花市","普洱市","平凉市"]},{"letter":"Q","list":["秦皇岛市","齐齐哈尔市","七台河市","衢州市","泉州市","青岛市","潜江市","清远市","钦州市","琼海市","琼中黎族苗族自治县","黔西南布依族苗族自治州","黔东南苗族侗族自治州","黔南布依族苗族自治州","曲靖市","庆阳市"]},{"letter":"R","list":["日照市","日喀则市"]},{"letter":"S","list":["石家庄市","朔州市","沈阳市","四平市","松原市","双鸭山市","绥化市","上海市","苏州市","宿迁市","绍兴市","宿州市","厦门市","三明市","上饶市","三门峡市","商丘市","十堰市","随州市","神农架林区","邵阳市","韶关市","深圳市","汕头市","汕尾市","三亚市","三沙市","遂宁市","山南市","商洛市","石嘴山市","石河子市","双河市"]},{"letter":"T","list":["天津市","唐山市","太原市","通辽市","铁岭市","通化市","泰州市","台州市","铜陵市","泰安市","漯河市","天门市","屯昌县","铜仁市","铜川市","天水市","吐鲁番市","塔城地区","图木舒克市","铁门关市","台湾省"]},{"letter":"W","list":["乌海市","乌兰察布市","无锡市","温州市","芜湖市","潍坊市","威海市","武汉市","梧州市","五指山市","文昌市","万宁市","文山壮族苗族自治州","渭南市","武威市","吴忠市","乌鲁木齐市","五家渠市"]},{"letter":"X","list":["邢台市","忻州市","兴安盟","锡林郭勒盟","徐州市","宣城市","新余市","新乡市","许昌市","信阳市","襄阳市","孝感市","咸宁市","仙桃市","湘潭市","湘西土家族苗族自治州","西双版纳傣族自治州","西安市","咸阳市","西宁市","香港特别行政区"]},{"letter":"Y","list":["阳泉市","运城市","营口市","延边朝鲜族自治州","伊春市","盐城市","扬州市","鹰潭市","宜春市","烟台市","宜昌市","岳阳市","益阳市","永州市","阳江市","云浮市","玉林市","宜宾市","雅安市","玉溪市","延安市","榆林市","玉树藏族自治州","银川市","伊犁哈萨克自治州"]},{"letter":"Z","list":["张家口市","朝阳市","镇江市","舟山市","漳州市","淄博市","枣庄市","郑州市","周口市","驻马店市","株洲市","张家界市","珠海市","湛江市","肇庆市","中山市","重庆市","自贡市","资阳市","遵义市","昭通市","张掖市","中卫市"]}];
    var CityIndex = ["A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","W","X","Y","Z"];
    var CityHots = ["北京市","长春市","常州市","长沙市","大连市","贵阳市","广州市","哈尔滨市","济南市","昆明市","宁波市","青岛市","上海市","深圳市","无锡市","西安市","厦门市","郑州市"];

    // 渲染热门城市
    var hotDom = '';
    $.each(CityHots,function (index, value) {
        hotDom += '<div class="city-button" data-city="'+value+'">'+value+'</div>';
    });
    $('.line-1').html(hotDom);

    //渲染城市列表
    var cityDom = '';
    $.each(cityList,function (index,item) {
        var letter = '<div class="city-part" id="CitySelector-'+item.letter +'"><span class="city-list">'+item.letter +'</span>';
        var citys = '';
        $.each(item.list,function (i, city) {
            citys += '<div class="city-item" data-city="'+city+'">'+city+'</div>';
        });
        cityDom += letter + citys + '</div>';
    });
    $('.city-all').html(cityDom);

    // 渲染字母表
    var letDom = '';
    $.each(CityIndex,function (index, value) {
        letDom += '<a href="#CitySelector-'+value+'">'+value+'</a>';
    });
    $('.nav-bar').append(letDom);
})();

// 城市点击事件
function selected(e){
    var selCity = e.target.getAttribute('data-city');
    if(selCity){
        globalData.choosecity = selCity;
        globalData.chooseprov = globalData.cityToProvince[selCity];
        $(".sel-city").html(selCity);
        $('#CitySelector').fadeOut();
    }
}

/** -====== SEM参数 =====-*/
        (function () {
            var doc_reffer = document.referrer.split("?")[1];
            try {
                var str2 = decodeURI(doc_reffer);
            } catch (e) {
                var str2 = "";
            }
            try {
                var str = decodeURI(window.location.href.split('?')[1]);
            } catch (e) {
                var str = "";
            }

            function GetQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = str.match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }

            function GetReferrer(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = str2.match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }

            var word = GetReferrer("word");//!!!!! 百度的搜索词 pc的关键词是“wd”，手机百度的关键词是“word”
            var query = GetReferrer("query");//搜狗的搜索词
            var source = GetQueryString("source");
            var plan = GetQueryString("plan");
            var unit = GetQueryString("unit");
            var keyword = GetQueryString("keyword");
            var e_keywordid = GetQueryString("e_keywordid");
            var e_matchtype = GetQueryString("e_matchtype");
            var e_creative = GetQueryString("e_creative");
            var e_adposition = GetQueryString("e_adposition");
            var e_pagenum = GetQueryString("e_pagenum");
            var semWords = {
                source: source ? source : '',
                word: word || query || '',
                plan: plan ? plan : '',
                unit: unit ? unit : '',
                keyword: keyword ? keyword : '',
                e_keywordid: e_keywordid ? e_keywordid : '',
                e_matchtype: e_matchtype ? e_matchtype : '',
                e_creative: e_creative ? e_creative : '',
                e_adposition: e_adposition ? e_adposition : '',
                e_pagenum: e_pagenum ? e_pagenum : '',
                UrlReferrer: decodeURI(location.href) ? decodeURI(location.href) : '',
            };
            console.log(semWords);
            if (semWords.source || semWords.plan || semWords.unit || semWords.keyword || semWords.e_keywordid || semWords.e_matchtype
                || semWords.e_creative || semWords.e_adposition || semWords.e_pagenum || semWords.UrlReferrer) {
                semWords = JSON.stringify(semWords);
                globalData.sem = semWords;
            }
        })();
